package com.mt.customer.service.impl;

import java.util.List;
import java.util.Map;


import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.customer.api.service.IContractService;
import com.mt.customer.entity.ContractEntity;
import com.mt.customer.service.model.ContractServiceModel;
import org.springframework.stereotype.Service;

/**
 * 电子合同
 */
@Service
public class ContractServiceImpl implements IContractService {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ContractServiceImpl.class);

    @Autowired
    private ContractServiceModel contractServiceModel;

    public ServiceResult<List<ContractEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<ContractEntity>> result = null;
        try {
            result = contractServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[ContractServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }
        return result;
    }

    public ServiceResult<ContractEntity> findInfo(Map<String, Object> params) {
        ServiceResult<ContractEntity> result = null;
        try {
            result = contractServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[ContractServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<Integer> doInsert(ContractEntity contractEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = contractServiceModel.insert(contractEntity);
        } catch (Exception e) {
            LOGGER.error("[ContractServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer contractId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = contractServiceModel.deleteByPrimaryKey(contractId);
        } catch (Exception e) {
            LOGGER.error("[ContractServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(ContractEntity contractEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = contractServiceModel.updateRelate(contractEntity);
        } catch (Exception e) {
            LOGGER.error("[ContractServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }
}
